import {
    quicktype,
    InputData,
    jsonInputForTargetLanguage,
    JSONSchemaInput,
    FetchingJSONSchemaStore,
  } from 'quicktype-core'
  async function quicktypeJSON(targetLanguage:any, typeName:any, jsonString:any) {
    const jsonInput = jsonInputForTargetLanguage(targetLanguage)
  
    // We could add multiple samples for the same desired
    // type, or many sources for other types. Here we're
    // just making one type from one piece of sample JSON.
    await jsonInput.addSource({
      name: typeName,
      samples: [jsonString],
    })
  
    const inputData = new InputData()
    inputData.addInput(jsonInput)
  
    return await quicktype({
      inputData,
      lang: targetLanguage,
    })
  }
  
  async function quicktypeJSONSchema(targetLanguage:any, typeName:any, jsonSchemaString:any) {
    const schemaInput = new JSONSchemaInput(new FetchingJSONSchemaStore())
  
    // We could add multiple schemas for multiple types,
    // but here we're just making one type from JSON schema.
    await schemaInput.addSource({ name: typeName, schema: jsonSchemaString })
  
    const inputData = new InputData()
    inputData.addInput(schemaInput)
  
    return await quicktype({
      inputData,
      lang: targetLanguage,
    })
  }
  export async function jsonToOther(type: string, jsonString: string) {
    const { lines } = await quicktypeJSON(type, 'Person', jsonString)
    return lines.join('\n')
  }
  